package dataMigration;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Mysql implements DBconnect
{
	private String _username = "root";
	private String _password = ""; 
	
	private String _prefix = "jdbc:mysql:"; 
	
	private String _driver = "com.mysql.jdbc.Driver";
	private String _dsn;
	Connection connObject;
	Statement stmt;
	String _host = "localhost";
	String _database = "gui";
	
	public Connection getConnect()
	{
		setDSN();
		try{
	    	   Class.forName(_driver);
	    	   connObject=DriverManager.getConnection(_prefix+_dsn,_username,_password);
	       }catch(Exception e)
	       {
	    	   System.out.println("Error in getConnect() method");
	    	   e.printStackTrace();
	       }
		return connObject;
	}

	public Statement getStatement(Connection connObject) 
	{
		try 
		{
			return stmt=connObject.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return stmt;
	}

	void setDSN() {
		this._dsn = "//"+_host+"/"+_database;
	}

	public void setDriver(String _driver) {
		this._driver = _driver;
	}

	public void setPrefix(String _prefix) {
		this._prefix = _prefix;
	}

	public void setUsername(String _username) 
	{
		this._username = _username;
	}

	public void setPassword(String _password) {
		this._password = _password;
	}

	public void setDatabase(String _database) 
	{
		this._database = _database;
	}

	public void setHost(String _host) {
		this._host = _host;	
	}
	public static void main(String[] args) 
	{
		Mysql mysql = new Mysql();
		mysql.getConnect();
	}
}
